package com.ad.interceptors;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

/**
 * 验证权限的拦截器
 * 
 * @author Administrator
 * 
 */
public class AuthInterceptor extends MethodFilterInterceptor  {
	private final Log logger = LogFactory.getLog(getClass());
	/**
	 * a 广告主 b 微博主
	 */
	private String userType;
	
	public AuthInterceptor() {
		super();
	}
	public AuthInterceptor(String userType) {
		super();
		this.userType = userType;
	}
	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}
	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		Map session = invocation.getInvocationContext().getSession();
		Object obj = null;
		if ("a".equals(userType)) {
			obj = session.get("a_user");
		} else {
			obj = session.get("b_user");
		}
		
		logger.debug("authority intercept ....");
		if (null != obj) {
			return invocation.invoke();
		} else {
			return "index";
		}
	}
}
